home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/time.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- /* #include <netdb.h> */
- #include "inet.h"
-
- char msg[2000];
-
- struct timeval timeout = {0L, 0L};
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- extern char *optarg;
- int c, debugLevel = 0;
- char *host = 0;
-
- int cc;
- int i;
- int fd;
- fd_set readfds;
- int maxfds;
-
- FD_ZERO(&readfds);
-
- while ((c = getopt(argc,argv,"h:")) != EOF) {
- switch (c) {
- case 'h': host = optarg; break;
- default: exit(-1);
- }
- }
-
- maxfds = getdtablesize();
- /* prevent narrow fd_set binaries from blowing up with with */
- /* large getdtablesize() */
- #ifdef FD_SET_SIZE
- maxfds = ((FD_SET_SIZE > maxfds)?maxfds:FD_SET_SIZE);
- #endif
-
- fd = initport(PORT_NUMBER(2000),CLIENT,SOCK_STREAM,host);
-
- if (fd < 0) {
- fprintf(stderr,"initport() = %d\n",fd);
- exit(-1);
- }
- for (i=0;;i++) {
- printf("%d: ",i);
- if (0 == gets(msg)) exit(0); /* exit on EOF */
- cc = sized_write(fd,msg,strlen(msg)+1);
- FD_SET(fd,&readfds);
- if (0 < select(maxfds,&readfds,0,0,&timeout)
- && FD_ISSET(fd,&readfds)) {
- cc = sized_read(fd,msg,2000);
- msg[cc] = '\0';
- printf("msg from server: %s\n",msg);
- }
- }
- }
-